package org.example.day20240820;

import java.util.Arrays;

public class StringDemo {
    public static void main(String[] args) {
        String msg = "hello world kitty";

        System.out.println(msg.substring(6,11));

        char[] arrs = {'h','a','b'};
        String info = new String(arrs);
        System.out.println(info);//字符数组转字符串

        int index = msg.indexOf("world");
        System.out.println(index);//包含返回下标，不包含返回-1

        System.out.println(msg.contains(" "));
        System.out.println(msg.startsWith("hell"));
        System.out.println(msg.endsWith("kitty"));

        String newMsg = msg.replace("kitty","nihao");
        System.out.println(newMsg);
        String[] arr = msg.split(" ");
        System.out.println(Arrays.toString(arr));
        System.out.println(msg.length());
        System.out.println(msg.charAt(0));
        for(int i=0; i<msg.length(); i++){
            System.out.print(msg.charAt(i));
        }
        System.out.println();
        char[] charArr = msg.toCharArray();
        for(int i=0; i<charArr.length; i++){
            System.out.print(charArr[i]);
        }


    }
}
